package com.quanquan.store.service;

import cn.hutool.log.dialect.commons.ApacheCommonsLog;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.quanquan.store.alipay.Alipay;
import com.quanquan.store.configBean.RabbitSender;
import com.quanquan.store.dao.OrderCacheDao;
import com.quanquan.store.dto.KetopParkingRecordDTO;
import com.quanquan.store.dto.KetopVipDTO;
import com.quanquan.store.dto.UserDTO;
import com.quanquan.store.entity.GroupBuyingTradingRecord;
import com.quanquan.store.entity.Order;
import com.quanquan.store.entity.ShoppingKillTradingRecord;
import com.quanquan.store.request.*;
import com.quanquan.store.shenxinpay.ShenXinPay;
import com.quanquan.store.shenxinpay.enitiy.request.InstpayRequest;
import com.quanquan.store.shenxinpay.enitiy.response.InstpayResponse;
import commond.IntegralOutPut;
import exceptions.service.ServiceRuntimeException;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import utils.*;

import javax.net.ssl.SSLContext;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.security.KeyStore;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 功能描述:
 *
 * @ClassName: WxPayService
 * @Author: xiaoqianh丶
 * @Date: 2019-07-01 16:56
 * @Version: V1.0
 */

@Service
public class WxPayService extends BaseService {

    private final ShoppingKillTradingRecordService shoppingKillTradingRecordService;
    private final OrderService orderService;
    private final RabbitSender rabbitSender;
    @Autowired
    private CouponService couponService;
    @Autowired
    private GroupBuyingTradingRecordService groupBuyingTradingRecordService;
    private ApacheCommonsLog log;
    @Autowired
    private Alipay alipay;
    @Autowired
    private OrderCacheDao orderCacheDao;


    @Autowired
    public WxPayService(ShoppingKillTradingRecordService shoppingKillTradingRecordService, OrderService orderService, RabbitSender rabbitSender) {
        this.shoppingKillTradingRecordService = shoppingKillTradingRecordService;
        this.orderService = orderService;
        this.rabbitSender = rabbitSender;
    }

    @Value("${wx-pay.appid}")
    private String appid;

    @Value("${wx-pay.mchid}")
    private String mchid;

    @Value("${wx-pay.secert}")
    private String secert;

    @Value("${wx-pay.notifyUrl}")
    private String notifyKillUrl;

    @Value("${wx-pay.notifyBuyUrl}")
    private String notifyBuyUrl;

    @Value("${wx-pay.refund-url}")
    private String refundUrl;

    @Value("${wx-pay.refundNotify-url}")
    private String refundNotifyUrl;

    @Value("${wx-pay.notifyParkingUrl}")
    private String notifyParkingUrl;

    @Value("${wx-pay.tradeType}")
    private String tradeType;

    @Value("${wx-pay.payUrl}")
    private String payUrl;

    @Value("${module-url.parkingUrl}")
    private String parkingUrl;

    @Value("${module-url.userUrl}")
    private String userUrl;

    @Value("${wx-pay.ketopVipNotifyUrl}")
    private String ketopVipNotifyUrl;

    @Value("${wx-pay.callBack}")
    private String callBack;


    public Map<String, Object> wxPay(WxPayRequest wxPayRequest) {

        Map<String, Object> response = new HashMap<String, Object>();// 返回给小程序端需要的参数
        String orderNum = wxPayRequest.getOrderNum();
        String openId = wxPayRequest.getOpenId();
        try {
            // 生成的随机字符串
            String nonce_str = StringUtils.getRandomStringByLength(32);
            // 获取客户端的ip地址
            String spbill_create_ip = "127.0.0.1";
            // 组装参数，用户生成统一下单接口的签名
            Map<String, String> packageParams = new HashMap<String, String>();
            // 商品名称
            String body = null;
            String notifyUrl = null;
            String price = null;
            if (wxPayRequest.getType() == 1) {
                body = "秒杀商品支付";
                notifyUrl = notifyKillUrl;
                ShoppingKillTradingRecord order = shoppingKillTradingRecordService.findByOrderRecord(orderNum);
                if (order == null) {
                    response.put("msg", "未查询到秒杀订单");
                    return response;
                }
                Double priceD = order.getPrice() * 100;
                price = String.valueOf(priceD.intValue());
            } else if (wxPayRequest.getType() == 2) {
                body = "购买商品支付";
                notifyUrl = notifyBuyUrl;
                Order order = null;
                String s = orderCacheDao.get(orderNum);
                if (s!=null){
                    order = orderService.findByOrderNum(orderNum);
                }
                if (order == null) {
                    response.put("msg", "未查询到订单信息");
                    return response;
                }
                Double priceD = order.getPrice() * 100;
                price = String.valueOf(priceD.intValue());
            } else if (wxPayRequest.getType() == 3) {
                notifyUrl = notifyParkingUrl;
                PayParkingFeeRequest payParkingFeeRequest = new PayParkingFeeRequest();
                payParkingFeeRequest.setOrderNo(orderNum);
                String postJson = Request.postJson(parkingUrl + "/ketop_parking/query_by_parking_order_num", payParkingFeeRequest);
                JSONObject jsonObject = JSON.parseObject(postJson);
                if (null == jsonObject) {
                    response.put("msg", "未查询到停车订单");
                    return response;
                }
                Integer resCode = jsonObject.getInteger("resCode");
                KetopParkingRecordDTO data = new KetopParkingRecordDTO();
                if (0 == resCode) {
                    data = jsonObject.getJSONObject("data").toJavaObject(KetopParkingRecordDTO.class);
                }
                //备注车牌
                body = data.getPlateNum() + " - 小程序停车支付";
                Integer priceD = data.getFee();
                price = String.valueOf(priceD.intValue());
            } else if (wxPayRequest.getType() == 5) {
                body = "团购商品支付";
                notifyUrl = callBack;
                GroupBuyingTradingRecord order = groupBuyingTradingRecordService.findByOrderRecord(orderNum);
                if (order == null) {
                    response.put("msg", "未查询到订单信息");
                    return response;
                }
                Double priceD = order.getPrice() * 100;
                price = String.valueOf(priceD.intValue());
            } else {
                notifyUrl = ketopVipNotifyUrl;
                KetopVipRequest ketopVipRequest = new KetopVipRequest();
                ketopVipRequest.setOrderNo(orderNum);
                String postJson = Request.postJson(parkingUrl + "/ketop_vip/get_order_by_order_no", ketopVipRequest);
                JSONObject jsonObject = JSON.parseObject(postJson);
                if (null == jsonObject) {
                    response.put("msg", "未查询到订单");
                    return response;
                }
                Integer resCode = jsonObject.getInteger("resCode");
                KetopVipDTO data = new KetopVipDTO();
                if (0 == resCode) {
                    data = jsonObject.getJSONObject("data").toJavaObject(KetopVipDTO.class);
                }
                //备注车牌
                body = "月租车充值";
                Integer priceD = data.getFee();
                price = String.valueOf(priceD.intValue());
            }
            packageParams.put("appid", appid);// 商户appid
            packageParams.put("mch_id", mchid);// 商户id
            packageParams.put("nonce_str", nonce_str);// 32位随机字符串
            packageParams.put("body", body);// 商品名称
            packageParams.put("out_trade_no", orderNum);// 商户订单号
            packageParams.put("total_fee", price);// 支付金额，这边需要转成字符串类型，否则后面的签名会失败
            packageParams.put("spbill_create_ip", spbill_create_ip);// 客户端的ip地址
            packageParams.put("notify_url", notifyUrl);// 支付成功后的回调地址
            packageParams.put("trade_type", tradeType);// 支付方式
            packageParams.put("openid", openId);// 微信openid
            String now = DateUtils.getDateAfterMinute(0);
            String after = DateUtils.getDateAfterMinute(2);
            packageParams.put("time_start", now);
            packageParams.put("time_expire", after);
            String prestr = PayUtils.createLinkString(packageParams); // 把数组所有元素，按照“参数=参数值”的模式用“&”字符拼接成字符串
            // MD5运算生成签名，这里是第一次签名，用于调用统一下单接口
            String mysign = PayUtils.sign(prestr, secert, "utf-8").toUpperCase();
            // 拼接统一下单接口使用的xml数据，要将上一步生成的签名一起拼接进去
            String xml = "<xml>" + "<appid>" + appid + "</appid>" + "<body><![CDATA[" + body + "]]></body>"
                    + "<mch_id>" + mchid + "</mch_id>" + "<nonce_str>" + nonce_str + "</nonce_str>"
                    + "<notify_url>" + notifyUrl + "</notify_url>" + "<openid>" + openId
                    + "</openid>" + "<out_trade_no>" + orderNum + "</out_trade_no>"
                    + "<spbill_create_ip>" + spbill_create_ip + "</spbill_create_ip>" + "<total_fee>" + price
                    + "</total_fee>" + "<trade_type>" + tradeType + "</trade_type>" + "<sign>" + mysign
                    + "</sign>" + "<time_start>" + now + "</time_start>"
                    + "<time_expire>" + after + "</time_expire>" + "</xml>";
            System.out.println("调试模式_统一下单接口 请求XML数据：" + xml);
            // 调用统一下单接口，并接受返回的结果
            String result = PayUtils.httpRequest(payUrl, "POST", xml);
            System.out.println("调试模式_统一下单接口 返回XML数据：" + result);
            // 将解析结果存储在HashMap中
            @SuppressWarnings("rawtypes")
            Map map = PayUtils.doXMLParse(result);
            String return_code = (String) map.get("return_code");// 返回状态码
            if (return_code.equals("SUCCESS")) {
                String prepay_id = (String) map.get("prepay_id");// 返回的预付单信息
                response.put("nonceStr", nonce_str);
                response.put("package", "prepay_id=" + prepay_id);
                Long timeStamp = System.currentTimeMillis() / 1000;
                response.put("timeStamp", timeStamp + "");// 这边要将返回的时间戳转化成字符串，不然小程序端调用wx.requestPayment方法会报签名错误
                // 拼接签名需要的参数
                String stringSignTemp = "appId=" + appid + "&nonceStr=" + nonce_str + "&package=prepay_id="
                        + prepay_id + "&signType=MD5&timeStamp=" + timeStamp;
                // 再次签名，这个签名用于小程序端调用wx.requesetPayment方法
                String paySign = PayUtils.sign(stringSignTemp, secert, "utf-8").toUpperCase();
                response.put("paySign", paySign);
                response.put("signType", "MD5");
            }
            response.put("appId", appid);
            return response;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public Map<String, Object> createParkingOrder(WxPayRequest wxPayRequest) {
        // 获取客户端的ip地址
        Map<String, Object> response = new HashMap<>();
        UserRequestBody userRequestBody = new UserRequestBody();
        //通过openid查找用户
        userRequestBody.setUserId(wxPayRequest.getUserId());
        String postJson1 = Request.postJson(userUrl + "/user/qurey_by_user_id", userRequestBody);
        JSONObject jsonObject1 = JSON.parseObject(postJson1);
        if (null == jsonObject1) {
            response.put("msg", "用户系统异常");
            return response;
        }
        Integer resCode1 = jsonObject1.getInteger("resCode");
        UserDTO data1;
        if (0 == resCode1) {
            data1 = jsonObject1.getJSONObject("data").toJavaObject(UserDTO.class);
        } else {
            response.put("msg", "未查询到该用户");
            return response;
        }
        //查询车费，并生成预支付停车订单
        UserCarKetopRequest userCarKetopRequest = new UserCarKetopRequest();
        userCarKetopRequest.setPlateNum(wxPayRequest.getPlateNum());
        userCarKetopRequest.setUserId(wxPayRequest.getUserId());
        userCarKetopRequest.setDisType(4);
        userCarKetopRequest.setType(1);
        String postJson = Request.postJson(parkingUrl + "/ketop_parking/query_fee_and_create_order", userCarKetopRequest);
        System.out.println(postJson);
        JSONObject jsonObject = JSON.parseObject(postJson);
        if (null == jsonObject) {
            response.put("msg", "停车系统异常");
            return response;
        }
        KetopParkingRecordDTO data;
        if (jsonObject.containsKey("resCode") && jsonObject.getInteger("resCode") == 0) {
            data = jsonObject.getJSONObject("data").toJavaObject(KetopParkingRecordDTO.class);
            if (data.getTotalFee() == 0) {
                response.put("msg", "未查询到停车订单");
                return response;
            } else {
                //生成微信支付订单
                WxPayRequest wxPayRequest1 = new WxPayRequest();
                wxPayRequest1.setType(3);
                wxPayRequest1.setOrderNum(data.getOrderNo());
                wxPayRequest1.setOpenId(data1.getOpenid());
               /* DecimalFormat df = new DecimalFormat("0.00");
                double fee1 = data.getFee().doubleValue();
                String feeYuan = df.format(fee1 / 100);*/
                System.out.println("调起支付");
                return wxPay(wxPayRequest1);
            }
        } else {
            response.put("msg", "未查询到停车订单");
            return response;
        }
    }

    public String createParkingOrder(AlipayRequest alipayRequest) {
        // 获取客户端的ip地址
        Map<String, Object> response = new HashMap<>();
        UserRequestBody userRequestBody = new UserRequestBody();
        //查询车费，并生成预支付停车订单
        UserCarKetopRequest userCarKetopRequest = new UserCarKetopRequest();
        userCarKetopRequest.setPlateNum(alipayRequest.getPlateNum());
        String postJson = Request.postJson(parkingUrl + "/ketop_parking/query_fee_and_create_alipay_order", userCarKetopRequest);
        JSONObject jsonObject = JSON.parseObject(postJson);
        if (null == jsonObject) {
            return null;
        }
        Integer resCode = jsonObject.getInteger("resCode");
        if (resCode == 10013) {
            return null;
        }
        KetopParkingRecordDTO data;
        if (0 == resCode) {
            data = jsonObject.getJSONObject("data").toJavaObject(KetopParkingRecordDTO.class);
            Integer fee = data.getFee();
            if (data.getTotalFee() == 0) {
                return null;
            }
            DecimalFormat df = new DecimalFormat("0.00");
            String page = null;
            try {
                page = alipay.alipayPage(data.getFee(), data.getOrderNo(), "http://huanlegang.xiaooo.club/park/success.html");
            } catch (Exception e) {

            }
            return page;


        }
        return null;
    }


    /**
     * 退款逻辑
     *
     * @param orderNum
     * @throws Exception
     */
    public void refundOrder(String orderNum) throws Exception {
        GroupBuyingTradingRecord order = groupBuyingTradingRecordService.findByOrderRecord(orderNum);
        System.out.println("查询到订单"+ order);
        String transactionId = order.getTransactionId();
        if (StringUtils.isEmpty(transactionId)) {
            throw new ServiceRuntimeException("会话Id不能为空");
        }
        String orderIncrementId = UUIDGenerator.getUUIDforMySql();
        Double priceD = order.getPrice() * 100;
        String price = String.valueOf(priceD.intValue());

        String nonceStr = StringUtils.getRandomStringByLength(32);
        SortedMap<String, String> params = new TreeMap<>();
        params.put("appid", appid);
        params.put("mch_id", mchid);
        params.put("nonce_str", nonceStr);
        params.put("out_trade_no", orderNum);
        params.put("out_refund_no", orderIncrementId);
        params.put("total_fee", price);
        params.put("refund_fee", price);
//        params.put("transaction_id", transactionId);
        params.put("notify_url", refundNotifyUrl);
        params.put("sign", sign(params));
        System.out.println("params....+++" +params);
        String xml = PayUtils.parseParam2Xml(params);
        System.out.println("xml..."+xml);
        KeyStore keyStore = KeyStore.getInstance("PKCS12");
        InputStream in = this.getClass().getClassLoader().getResourceAsStream("security/apiclient_cert.p12");
        System.out.println("in...."+in);
        try {
            keyStore.load(in, mchid.toCharArray());
            String res = HttpUtil.doPostXmlSSL(refundUrl, xml, keyStore, mchid);
            System.out.println("res........"+res);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            in.close();
        }
    }

    private String sign(Map<String, String> params) {
        String linkStr = PayUtils.createLinkString(params);
        String sign = PayUtils.sign(linkStr, secert, StandardCharsets.UTF_8.name()).toUpperCase();
        return sign;
    }

    /**
     * 生成科拓vip预定单
     *
     * @param wxPayRequest
     * @return
     */
    public Map<String, Object> createKetopVip(WxPayRequest wxPayRequest) {
        Map<String, Object> response = new HashMap<>();
        UserRequestBody userRequestBody = new UserRequestBody();
        //通过用户id查找用户
        userRequestBody.setUserId(wxPayRequest.getUserId());
        String postJson1 = Request.postJson(userUrl + "/user/qurey_by_user_id", userRequestBody);
        JSONObject jsonObject1 = JSON.parseObject(postJson1);
        if (null == jsonObject1) {
            response.put("msg", "系统异常");
            return response;
        }
        Integer resCode1 = jsonObject1.getInteger("resCode");
        UserDTO data1;
        if (0 == resCode1) {
            data1 = jsonObject1.getJSONObject("data").toJavaObject(UserDTO.class);
            //预留备用，考虑到后期可能会用到积分时，此处释放就可以判断用户积分是否够用
            /*Integer integral = data1.getIntegral();
            if (integral < wxPayRequest.getSumIntegral()) {
                response.put("msg", "用户积分不足");
                return response;
            }*/
        } else {
            response.put("msg", "未查询到该用户");
            return response;
        }
        //查询车费，并生成预支付停车订单
        KetopVipRequest ketopVipRequest = new KetopVipRequest();
        ketopVipRequest.setPlateNum(wxPayRequest.getPlateNum());
        ketopVipRequest.setUserId(wxPayRequest.getUserId());
        String postJson = Request.postJson(parkingUrl + "/ketop_vip/create_ketop_vip", ketopVipRequest);
        JSONObject jsonObject = JSON.parseObject(postJson);
        if (null == jsonObject) {
            response.put("msg", "系统异常");
            return response;
        }
        Integer resCode = jsonObject.getInteger("resCode");
        KetopVipDTO data;
        if (0 == resCode) {
            data = jsonObject.getJSONObject("data").toJavaObject(KetopVipDTO.class);
            Integer fee = data.getFee();
            if (fee == 0) {
                response.put("msg", "未查询到订单");
                return response;
            } else {
                //生成微信支付订单
                WxPayRequest wxPayRequest1 = new WxPayRequest();
                wxPayRequest1.setType(4);
                wxPayRequest1.setOrderNum(data.getOrderNo());
                wxPayRequest1.setOpenId(data1.getOpenid());
                return wxPay(wxPayRequest1);
            }
        } else {
            response.put("msg", "未查询到订单");
            return response;
        }
    }

    public Map<String, Object> createParkingOrderOld(WxPayRequest wxPayRequest) {
        Map<String, Object> response = new HashMap<>();
        UserRequestBody userRequestBody = new UserRequestBody();
        //通过openid查找用户
        userRequestBody.setUserId(wxPayRequest.getUserId());
        String postJson1 = Request.postJson(userUrl + "/user/qurey_by_user_id", userRequestBody);
        JSONObject jsonObject1 = JSON.parseObject(postJson1);
        if (null == jsonObject1) {
            response.put("msg", "系统异常");
            return response;
        }
        Integer resCode1 = jsonObject1.getInteger("resCode");
        UserDTO data1;
        if (0 == resCode1) {
            data1 = jsonObject1.getJSONObject("data").toJavaObject(UserDTO.class);
            Integer integral = data1.getIntegral();
            if (integral < wxPayRequest.getSumIntegral()) {
                response.put("msg", "用户积分不足");
                return response;
            }
        } else {
            response.put("msg", "未查询到该用户");
            return response;
        }
        //查询车费，并生成预支付停车订单
        UserCarKetopRequest userCarKetopRequest = new UserCarKetopRequest();
        userCarKetopRequest.setPlateNum(wxPayRequest.getPlateNum());
        userCarKetopRequest.setUserId(wxPayRequest.getUserId());
        if (wxPayRequest.getSumIntegral() == null) {
            userCarKetopRequest.setIntegral(0);
        } else {
            userCarKetopRequest.setIntegral(wxPayRequest.getSumIntegral());
        }
        if (wxPayRequest.getUserDiscount() == null) {
            userCarKetopRequest.setUserDiscount(0);
        } else {
            userCarKetopRequest.setUserDiscount(wxPayRequest.getUserDiscount());
        }

        String postJson = Request.postJson(parkingUrl + "/ketop_parking/query_fee_and_create_order_old", userCarKetopRequest);
        JSONObject jsonObject = JSON.parseObject(postJson);
        if (null == jsonObject) {
            response.put("msg", "系统异常");
            return response;
        } else {
            if (jsonObject.containsKey("resCode") && jsonObject.getInteger("resCode") == 0) {
                KetopParkingRecordDTO data = jsonObject.getJSONObject("data").toJavaObject(KetopParkingRecordDTO.class);
                Integer fee = data.getFee();
                if (data.getTotalFee() <= 0) {
                    response.put("msg", "未查询到停车订单");
                    return response;
                } else {
                    if (fee <= 0) {
                        if (wxPayRequest.getSumIntegral() > 0) {
                            IntegralOutPut integralOutPut = new IntegralOutPut();
                            integralOutPut.setIntegralPoint(data.getIntegral().toString());
                            integralOutPut.setOrderNum(data.getOrderNo());
                            integralOutPut.setUserId(data.getUserId());
                            integralOutPut.setSource("积分抵扣停车费");
                            integralOutPut.setTradeAction(1);
                            integralOutPut.setForeignKeyId(data.getOrderNo());
                            integralOutPut.setRemark("景枫小程序停车 - " + data.getPlateNum());
                            DecimalFormat df = new DecimalFormat("0.00");
                            String str = df.format(data.getTotalFreeFee() / 100);
                            integralOutPut.setTradingContent("停车抵扣金额:" + str + "元");
                            integralOutPut.setConsumeType("parking");
                            String postJson3 = Request.postJson(userUrl + "/integral_details/check_Integral_deduct", integralOutPut);
                            JSONObject jsonObjec3 = JSON.parseObject(postJson3);
                            if (null == jsonObjec3) {
                                response.put("msg", "系统异常");
                                return response;
                            } else {
                                if (jsonObjec3.containsKey("resCode") && jsonObjec3.getInteger("resCode") == 0) {
                                    //如果待支付金额为0，直接更新订单为已支付
                                    PayParkingFeeRequest parkingRecordRequest1 = new PayParkingFeeRequest();
                                    parkingRecordRequest1.setOrderNo(data.getOrderNo());
                                    parkingRecordRequest1.setAmount(0);
                                    parkingRecordRequest1.setDiscount(0);
                                    parkingRecordRequest1.setFreeTime(0);
                                    parkingRecordRequest1.setFreeMoney(data.getTotalFreeFee());
                                    List<FreeDetail> freeDetails = new LinkedList<>();
                                    FreeDetail freeDetail = new FreeDetail();
                                    freeDetail.setType(0);
                                    freeDetail.setMoney(data.getTotalFreeFee());
                                    freeDetail.setTime(0);
                                    freeDetail.setCode(data1.getId());
                                    freeDetails.add(freeDetail);
                                    parkingRecordRequest1.setFreeDetail(freeDetails);
                                    //同步订单
                                    String s = Request.postJson(parkingUrl + "/ketop_parking/get_payment_recharge_old", parkingRecordRequest1);
                                    JSONObject jsonObject2 = JSON.parseObject(s);
                                    Integer resCode2 = jsonObject2.getInteger("resCode");
                                    if (resCode2 == 0) {
                                        //扣减用户积分
                                        response.put("msg", "已完成订单");
                                        //发送任务队列，完成签到任务
                                        Map<String, Object> properties = new HashMap<>();
                                        properties.put("userId", data.getUserId());
                                        properties.put("taskType", "parking");
                                        //将计算结果放到MQ队列去补充明细的余额
                                        String msg = "补全积分明细余额";
                                        String exchange = "task.exchange";
                                        String routingKey = "task.sign";
                                        rabbitSender.sendMessageToMQ(msg, properties, exchange, routingKey);
                                        return response;
                                    } else {
                                        response.put("msg", "积分抵扣失败");
                                        return response;
                                    }
                                } else {
                                    response.put("msg", "积分抵扣失败");
                                    return response;
                                }
                            }
                        }
                    } else {
                        //生成微信支付订单
                        WxPayRequest wxPayRequest1 = new WxPayRequest();
                        wxPayRequest1.setType(3);
                        wxPayRequest1.setOrderNum(data.getOrderNo());
                        wxPayRequest1.setOpenId(data1.getOpenid());
                        return wxPay(wxPayRequest1);
                    }
                }
            } else {
                response.put("msg", "未查询到停车订单");
                return response;
            }
        }

        response.put("msg", "未查询到停车订单");
        return response;
    }





}
